% =========================================================================
% Schniepp Lab, 2018-2021
% Calculate sub-peaks using multi-curve method
% dimension of parGuess:
% (m*2+3)*n
% positions - positions for each sub-peak,
%     first line in pars
% width - width for each sub-peak
%     second line in pars
% L - Lorenzian percentage for each sub-peak
%     third line in pars
% Rest of pars:
% curve 1 AG
% curve 1 AL
% curve 2 AG
% curve 2 AL
% ...
% curve n AG
% curve n AL
% =========================================================================
function pars=calSubPeaks(parGuess,x,y,lb,ub,mode,eTimes)
    % setup lsqcurvefit option
    if strcmp(mode,'Cal')
        options=optimoptions(@lsqcurvefit,'MaxFunEvals',eTimes,'MaxIter',25000);
        options.TolFun=1.0e-11;

        % solve lsq problem
        pars=lsqcurvefit(@MultiPeaksMultiCurves_ForOpt,parGuess,x,y,lb,ub,options);
    else
        pars=parGuess;
    end
end